﻿using System.Collections.Generic;
using System.Linq;
using Xc.DataAccess.Core.Extensions;

namespace Xc.DataAccess.Protocoals.WaterMeters.Models.Requests
{
    /// <summary>
    /// 多次卡充值
    /// </summary>
    public class SetMeterMutipleChargeRequest : MeterFrameTxBase, IUnit
    {
        /// <summary>
        /// 单位代码
        /// </summary>
        public byte UnitId { get; set; }

        internal protected override DataSegment DataSegment => DataSegment.SetMeterMutipleCharge;

       internal protected override FrameCommand Cmd => FrameCommand.CMD04;

        protected override void GetDataArea(List<byte> vs)
        {
            vs.Add(UnitId);
            List<byte> data = new List<byte>();
            var result=  ChargeValue.FromDeciamlUInt32LittleEndian(10.0M);
            data.AddRange(result.Take(3).ToArray());
            data.Add(0);
            byte[] array = new byte[] { 0x69, 0x12, 0x5A, 0x43 };
            for (int i = 0; i < array.Length; i++)
            {
                data[i]^=array[i];
            }
            vs.AddRange(data);
            vs.AddRange(Enumerable.Repeat<byte>(0,6)); ;
        }
        /// <summary>
        /// 充值量 m³ 0.1M
        /// </summary>
        public decimal ChargeValue { get; set; }
    }
}
